//
//  DCQuotationViewController.m
//  Driver
//
//  Created by 大橙子 on 2018/11/8.
//  Copyright © 2018 Tomous. All rights reserved.
//

#import "DCQuotationViewController.h"
#import "DCQuotationCell.h"
#import "DCProgressTool.h"
@interface DCQuotationViewController ()<UITableViewDelegate,UITableViewDataSource,quotationCellDelegate>

@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) NSMutableArray *dataSource;

@end

@implementation DCQuotationViewController
-(UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.width, ViewHeight-50) style:UITableViewStylePlain];
        _tableView.separatorStyle = UITableViewCellStyleDefault;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.backgroundColor = BackgroundColor;
    }
    return _tableView;
}
-(NSMutableArray *)dataSource
{
    if (!_dataSource) {
        _dataSource = [NSMutableArray new];
    }
    return _dataSource;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    NSArray *array = @[
                       @{
                           @"carrier":@"华阳",
                           @"time":@"2018-8-28 10:15:14",
                           @"type":@"待报价",
                           @"invoice":@"开票",
                           @"price":@"8000元",
                           @"start":@"北京市顺义区临河南大街9号",
                           @"end":@"上海市浦东区牌楼东路100号",
                           @"car":@"一手车",
                           @"num":@"6",
                           },
                       @{
                           @"carrier":@"长久",
                           @"time":@"2018-8-29 10:15:14",
                           @"type":@"已报价",
                           @"invoice":@"不开票",
                           @"price":@"8000元",
                           @"start":@"北京市顺义区临河南大街9号",
                           @"end":@"广州市浦东区牌楼东路100号",
                           @"car":@"二手车",
                           @"num":@"7",
                           },
                       @{
                           @"carrier":@"华阳",
                           @"time":@"2018-8-30 10:15:14",
                           @"type":@"已报价未完成",
                           @"invoice":@"开票",
                           @"price":@"8000元",
                           @"start":@"北京市顺义区临河南大街9号",
                           @"end":@"深圳市浦东区牌楼东路100号",
                           @"car":@"三手车",
                           @"num":@"8",
                           },
                       @{
                           @"carrier":@"长久",
                           @"time":@"2018-8-31 10:15:14",
                           @"type":@"已成交",
                           @"invoice":@"开票",
                           @"price":@"8000元",
                           @"start":@"北京市顺义区临河南大街9号",
                           @"end":@"天津市浦东区牌楼东路100号",
                           @"car":@"四手车",
                           @"num":@"9",
                           },
                       ];
    [self.dataSource removeAllObjects];
    self.dataSource = [DCQuotationModel mj_objectArrayWithKeyValuesArray:array];
    [self.view addSubview:self.tableView];
}
#pragma tableViewDelegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataSource.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    DCQuotationCell *cell = [DCQuotationCell cellWithTableView:tableView];
    cell.model = self.dataSource[indexPath.row];
    cell.delegate = self;
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    DCQuotationModel *model = self.dataSource[indexPath.row];
    if ([model.type isEqualToString:@"待报价"]) {
        return kBaseHeight*5-20;
    }
    return kBaseHeight*4-20;
//    return [DCQuotationCell getCellHeight];
}
#pragma quotationCellDelegate
-(void)selectedWithOfferBtn:(DCQuotationModel *)myModel
{
    [[UIApplication sharedApplication].keyWindow addSubview:[[DCProgressTool sharedHUDTool] showProgressTitle:@"提示" model:myModel type:0 sureBlock:^(NSString * _Nullable text) {
        DCLog(@"报价---%@",text);
    } cancleBlock:^(id  _Nonnull sender) {
        
    }]];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
